package File;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Test05 {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        String filename;
        boolean fileExists;
        File file;

        do {
            System.out.print("请输入文件名：");
            filename = scanner.nextLine();
            file = new File(filename);
            fileExists = file.exists();
            if (fileExists) {
                System.out.println("文件已存在，请更换文件名。");
            }
        } while (fileExists);

        try {
            file.createNewFile();
            System.out.println("文件创建成功。");
        } catch (IOException e) {
            System.out.println("文件创建失败。");
            e.printStackTrace();
        }
    }
}

